<template>
	<view class="">
		<view class="">
			<cu-custom bgColor="bg-gradual-orange" :isBack="true">
			    <block slot="backText">返回</block>
			    <block slot="content">我的</block>
			</cu-custom>
		</view>
		<view>
			<br>
			<button  @click="goto" class="cu-btn bg-red margin-tb-sm lg">菜单</button>
			<br>
				<button  @click="login()" class="cu-btn bg-red margin-tb-sm lg">登录测试</button>
			<br>
				<button  @click="wxTinyProgramPay()" class="cu-btn bg-red margin-tb-sm lg">支付!</button>
		</view>
	</view>
</template>

<script>
export default {
	data(){
		return{
			openId:"asd",
		}
	},
	methods:{
		goto(){
			console.log("llll")
			this.http
			  .get({
			    url: '/pro/list',
			  })
			  .then((data) => {
			    console.log(data)
			  })
		},
		
		login:function(){
				let self  = this;
				console.log("XXXXXXXXX");
				wx.login({
					success(res) {
						console.log(res.code);
						if(res.code){												
							wx.request({
								url : "https://localhost:9001/iou/weixin/wxTinyProgramLogin",
								data:{
									code:res.code
								},
								success(loginRes) {
									console.log(loginRes);
									//获取openId为
									console.log("openId为:");
									console.log(loginRes.data.DATA.openid);
									self.openId = loginRes.data.DATA.openid;
								}
							})
						}					
					}
				})
				//this.$data.openId = openIdSelf;
		},
		wxTinyProgramPay:function(){
			console.log("进行支付!")
			console.log("全局的openId为:");
			console.log(this.openId);
			
			console.log("调起支付,获取prepay_id");
			wx.request({
				url : "https://localhost:9001/weixinpay",
				data:{
					openid:this.openId
				},success(r) {
				  console.log(r);
				  console.log("AppId为");
				  console.log(r.data.DATA.appId);
				  console.log("nonceStr为");
				  console.log(r.data.DATA.nonceStr);
				  console.log("prepay_id为");
				  console.log(r.data.DATA.package);
				  console.log("paySign为");
				  console.log(r.data.DATA.paySign);
				  console.log("signType为");
				  console.log(r.data.DATA.signType);
				  console.log("timeStamp为")
				  console.log(r.data.DATA.timeStamp);
				  wx.requestPayment(
				  {
				  "timeStamp":r.data.DATA.timeStamp,
				  "nonceStr": r.data.DATA.nonceStr,
				  "package": r.data.DATA.package,
				  "signType": r.data.DATA.signType,
				  "paySign":r.data.DATA.paySign,
				  "success":function(res){},
				  "fail":function(res){},
				  "complete":function(res){}
				  })
				  
				  
				  
				}
			})
		}
	}
}
</script>

<style>
</style>
